package net.zdsoft.wpchat.support.action;

import net.zdsoft.keel.action.ActionContext;
import net.zdsoft.keel.page.TextImage;
import net.zdsoft.keel.util.RandomUtils;
import net.zdsoft.keel.util.ServletUtils;
import net.zdsoft.wpchat.android.client.BasicAction;

/**
 * 验证码生成Action
 * 
 * @author xuan
 * @version $Revision: 1.0 $, $Date: 2014-9-22 下午8:43:23 $
 */
public class VerifyImageAction extends BasicAction {
    private static final long serialVersionUID = 2135001306708370918L;

    public static final String VERIFY_CODE = "verifyCode";

    @Override
    public String execute() throws Exception {
        ServletUtils.clearCache(ActionContext.getResponse());

        String verifyCode = RandomUtils.getRandomNum(4);

        ActionContext.getSession().setAttribute(VERIFY_CODE, verifyCode);

        TextImage textImage = new TextImage(65, 24);
        textImage.setBgColor(0xff, 0xff, 0xff);
        textImage.setFontColor(0x99, 0x00, 0x00);
        textImage.setFont(24);
        textImage.setRandomPointNum(200);

        textImage.export(verifyCode, 3, 20, ActionContext.getResponse().getOutputStream());

        return SUCCESS;
    }

}
